This invention relates to improving the execution speed of C++ programs when C++ programs are compiled with a C++ compiler, and particularly to providing a C++ compile time optimization.
For a C++ hierarchy of classes, arguments can be passed in constructors. These constructor arguments can be further casted to different types through the constructor call, and through the prototype of the constructor arguments. In traditional models, this chain of casts can be a complex runtime expression, which is normal under the most pessimistic assumptions. Example 1 illustrates such a complex runtime expression:
 #include<stdio.h>class V  {  public:  virtual int f( ) { return ‘V’; };  int v;  };class A: public virtual V{  public:  virtual int f( ) {return ‘A’; };  int a;}; class B : public virtual V  {  public:  B(V *); //Here it is further casted to a V*  int f( ) { return ‘B’; }  int b;  }; class D: public virtual A, public virtual B {  public:  D( ) : B((A*)this) { } // Note the cast of this (which is a D * )  to an A*  int f( ) { return ‘D’; }  };B::B(V *v )  {   if( v->f( ) == ‘B’)    printf(“SUCCESSFUL!\n”);   else    printf(“FAILED!\n”);  }int main (void){ D d;}